package com.xu.cloud.controller;

import com.xu.cloud.feign.ProviderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerController {

    @Autowired
    private ProviderFeignClient providerFeignClient;  // 注入Feign客户端

    @RequestMapping(value = "/consumer/hello", method = RequestMethod.GET)
    public String hello() {
        return "Hello from consumer!";
    }
// 使用FeignClient调用服务提供者
    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo2(@PathVariable String str) {
        return providerFeignClient.echo(str);  // 调用Feign客户端的方法
    }
}